package com.ms.service.module.fish.message.server;

import java.nio.ByteBuffer;
import java.util.Collection;

import com.ms.service.module.fish.game.FishDesk;
import com.ms.service.module.fish.game.FishGlobal;
import com.ms.service.module.fish.game.GameConf;
import com.ms.service.module.fish.game.GameUser;
import com.ms.service.module.fish.game.KeepSeet;
import com.ms.service.module.fish.message.FishBaseMessage;

/**
 * 大厅机台信息
 * @author cuiwm
 */
public class RoomMessage extends FishBaseMessage {
	
    
    public RoomMessage() {
	}

	@Override
	public void writeBody(ByteBuffer buf) {
		Collection<FishDesk> desks = FishGlobal.getDesks();
		
		buf.putInt(GameConf.deskSize);
		buf.putInt(desks.size());
		for(FishDesk desk:desks) {
			buf.putInt(desk.getId());
			buf.put(desk.getType());
			buf.putInt(desk.getMsize());
			GameUser[] users = desk.getUsers();
			for(int i=0;i<users.length;i++){
				KeepSeet seet = desk.keepSeat(i);
				if(users[i] != null || seet != null) {
					buf.put((byte) i);
					if(users[i] != null){
						writeString(buf, users[i].getId().toString());
						buf.put((byte) users[i].getUser().getSex());
						buf.putInt(0);
					}else{
						writeString(buf, users[i].getId().toString());
						buf.put((byte) 3);
						buf.putInt(seet.getLeftTime());
					}
				}
			}
		}
	}


}